import type {
  CareType,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  DoctorPage,
  Image,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  PartialConsult,
  PayMoneyType,
  TopDep
} from '@/types/consult'
import { request } from '@/utils/request'

/**
 * 文章列表
 */
export const getKnowledgeList = (params: KnowledgeParams) => {
  return request<KnowledgePage>('patient/home/knowledge', 'GET', params)
}

/**
 * 医生列表
 */

export const doctorList = (params: PageParams) => {
  return request<DoctorPage>('home/page/doc', 'GET', params)
}

/**
 * 关注操作
 */

export const careHanler = (id: string, type: CareType) => {
  return request('like', 'POST', { id, type })
}

/**
 * 获取科室
 */

export const getAllDep = () => {
  return request<TopDep>('dep/all', 'GET')
}

/**
 *  文件上传
 */
// 文件上传的类型 File
export const uploadImage = (file: File) => {
  //Body 参数 (application/form-data) 所以必须要使用 FormData 格式, 要不然 application/form-data就会出现错误
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('upload', 'POST', fd)
}

import type { ConsultOrderPreData, ConsultOrderPreParams } from '@/types/consult'

// 获取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

/**
 * 支付生成订单
 */

export const payMoneyOrder = (params: PartialConsult) => {
  return request<{ id: string }>('/patient/consult/order', 'post', params)
}

/**
 * 支付接口
 */

export const getConsultOrderPayUrl = (params: PayMoneyType) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'post', params)
}

/**
 * 获取订单详情
 */

export const getConsultOrderDetail = (orderId: string) => {
  return request<ConsultOrderItem>('patient/consult/order/detail', 'GET', { orderId })
}

/**
 * 封装处方
 */

export const getPrescriptionPic = (id: string) => {
  return request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET')
}

/**
 * 评价医生
 */

export const evaluateConsultOrder = (evaluateObj: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => {
  return request('/patient/order/evaluate', 'POST', evaluateObj)
}

/**
 * 问诊记录
 */

export const getConsultOrderList = (params: ConsultOrderListParams) => {
  return request<ConsultOrderPage>('patient/consult/order/list', 'get', params)
}

// 取消订单
export const cancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')

/**
 * 删除订单
 */

export const deleteOrder = (id: string) => {
  return request(`patient/order/${id}`, 'DELETE')
}
